package com.zx.mes.hyl.security.core.validate.code.config;

import com.zx.mes.hyl.security.core.properties.SecurityProperties;
import com.zx.mes.hyl.security.core.validate.code.ValidateCodeGenerator;
import com.zx.mes.hyl.security.core.validate.code.image.ImageValidateCodeGenerator;
import com.zx.mes.hyl.security.core.validate.code.sms.SmsCodeSender;
import com.zx.mes.hyl.security.core.validate.code.sms.impl.DefaultSmsCodeSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * validateCodeBean 配置
 * @author huayunlong
 * @date 2018-6-1
 */
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    private SecurityProperties securityProperties;

    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ValidateCodeGenerator imageValidateCodeGenerator(){
        ImageValidateCodeGenerator codeGenerator = new ImageValidateCodeGenerator();
        codeGenerator.setSecurityProperties(securityProperties);
        return codeGenerator;
    }

    @Bean
    @ConditionalOnMissingBean(name = "defaultSmsCodeSender")
    public DefaultSmsCodeSender defaultSmsCodeSender(){
        return new DefaultSmsCodeSender();
    }
}
